package com.csht.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.csht.service.FindToService;

/**
 * 找回用户名和密码
 * @author chenhuiyan
 *
 */
@Controller
public class FindToController {
	
	@Autowired
	private FindToService findUsernameService;

	/**
	 * 找回用户名页面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/findusername")
	public String findUsername() throws Exception{
		return "/findTo/findUsername";
	}
	
	/**
	 * 根据手机号修改用户名
	 * @param userTel
	 * @param username
	 * @param redirectAttributes
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateUsername")
	public String updateUsername(@RequestParam(name = "userTel") String userTel, 
			@RequestParam(name = "userUsername") String username, RedirectAttributes redirectAttributes) 
			throws Exception{
		findUsernameService.updateUsername(userTel, username);
		redirectAttributes.addFlashAttribute("message", "成功");
		return "redirect:/findusername";
	}
	
	/**
	 * 找回密码页面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/findPassword")
	public String findPassword() throws Exception{
		return "/findTo/findPassword";
	}
	
	/**
	 * 根据手机号修改用户密码
	 * @param userTel
	 * @param userPassword
	 * @param redirectAttributes
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updatePassword")
	public String updatePassword(@RequestParam(name = "userTel") String userTel, 
			@RequestParam(name = "userPassword") String userPassword, RedirectAttributes redirectAttributes) 
			throws Exception{
		findUsernameService.updatePassword(userTel, userPassword);
		redirectAttributes.addFlashAttribute("message", "成功");
		return "redirect:/findPassword";
	}
}
